package com.dhwl.hsh.merchant.ui.activity;

import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.media.Image;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.dhwl.hsh.lib.utils.SystemBarTintManager;
import com.dhwl.hsh.lib.view.viewpagerindicator.IconPageIndicator;
import com.dhwl.hsh.lib.view.viewpagerindicator.LinePageIndicator;
import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.merchant.ui.adapter.GuideFragmentAdapter;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 引导页面
 *
 * @author Derek.Kidd
 * @time 2016/4/29 11:47
 */
public class GuideActivity extends BaseActivity {

    @Bind(R.id.guide_pager)
    ViewPager mPager;
    @Bind(R.id.guide_indicator)
    LinePageIndicator mIndicator;

    @Bind(R.id.btn_guide_pass)
    Button btnPass;

    private GuideFragmentAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        toggleHideyBar();


        mTintManager.setStatusBarTintColor(Color.TRANSPARENT);
        mTintManager.setNavigationBarTintEnabled(true);
        mTintManager.setNavigationBarTintColor(Color.TRANSPARENT);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            SystemBarTintManager.SystemBarConfig config = mTintManager.getConfig();

            RelativeLayout.LayoutParams layoutParams =
                    (android.widget.RelativeLayout.LayoutParams) mIndicator.getLayoutParams();

            layoutParams.setMargins(layoutParams.leftMargin,
                    layoutParams.topMargin,
                    layoutParams.rightMargin,
                    layoutParams.bottomMargin + config.getPixelInsetBottom());

            mIndicator.setLayoutParams(layoutParams);
        }


    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_guide;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        mAdapter = new GuideFragmentAdapter(getSupportFragmentManager());
        mPager.setAdapter(mAdapter);
        mIndicator.setViewPager(mPager);
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_guide_pass)
    public void onPassClick(View view) {

        startActivity(new Intent(this, LoginActivity.class));
        finish();

    }

    public void toggleHideyBar() {

        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();

        // Navigation bar hiding:  Backwards compatible to ICS.
        if (Build.VERSION.SDK_INT >= 14) {
            uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16) {
            uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }

        // Immersive mode: Backward compatible to KitKat.
        // Note that this flag doesn't do anything by itself, it only augments the behavior
        // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
        // all three flags are being toggled together.
        // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
        // Sticky immersive mode differs in that it makes the navigation and status bars
        // semi-transparent, and the UI flag does not get cleared when the user interacts with
        // the screen.
        if (Build.VERSION.SDK_INT >= 18) {
            uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
        getWindow().getDecorView().setSystemUiVisibility(uiOptions);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
        }

    }
}
